<include file="Public:head" title='订单详情' />
<script src="__PUBLIC__/js/Jquery/validate.js"></script>
<script type="text/javascript">
    $(function(){
        jQuery.validator.addMethod("checkStateDisable", function(value, element) {  
            var state = $("input[name=state]:checked").val();
            var is_true =true;
          
            if(state == 9){
                var  reason = $("input[name=reason]").val();
                if(reason == ''){
                    is_true =false;
                }
            }
            return is_true;
        }); 
        $("#form").validate({
            errorPlacement: function(error, element){
                var error_td = element.parent().parent();
                error_td.find('label.error').hide();
                error_td.append(error);
            },
            rules : {
                reason : {
                    checkStateDisable : true
                }
                
            },
            messages : {
                reason : {
                    checkStateDisable : '失效原因不能为空'
                }
                
            }
        });
    });
    function checkState(obj){
        if(obj.val() == 9){
            $("#state_input").show();
            $("input[name=reason]").focus();
        }else{
            $("#state_input").hide();
        }
    }
    function getReason(reason){
        $("input[name=reason]").val(reason)
    }
</script>
<div class="main-container" id="main-container">
    <div class="main-container-inner">
        <include file="Public:left" />
        <div class="main-content">
            <div class="breadcrumbs" id="breadcrumbs">
                <ul class="breadcrumb">
                    <li><i class="icon-home home-icon"></i><a href="__APP__/{$Think.MODULE_NAME}">首页</a></li>
                    <li><a href="{:U('Order/lists')}">订单管理</a></li>
                    <li class="active">订单详情</li>
                </ul>
            </div>
            <div class="page-content">
                <div class="row">
                    <div class="col-xs-12">
                        <div class="row">
                            <div class="col-xs-12">
                                <h3 class="header smaller lighter blue">订单详情</h3>
                                <form action="{:U('Order/detail_post')}" method="POST" id="form">
                                    <div class="table-responsive">
                                        <table class="table table-striped table-bordered table-hover table_detail">
                                            <tbody>
                                                <tr>
                                                    <td class="td_left">订单号</td>
                                                    <td>{$detail.ordernum}</td>
                                                </tr>
                                                <tr>
                                                    <td>下单时间:</td>
                                                    <td>
                                                        {$detail.addtime|date="Y-m-d H:i",###}
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>价格:</td>
                                                    <td>
                                                        <span>原价：{$detail['totalMoney']}</span>
                                                        <span style="margin:0 10px">折扣：{$detail['totalMoney']-$detail['realMoney']|getOneDot=###}元</span>
                                                        <span style="color:#E54920">应付：{$detail['realMoney']}元</span>

                                                    </td>
                                                </tr>

                                                <tr>
                                                    <td>店铺:</td>
                                                    <td>
                                                        <a href="{:U('Shop/detail',array('id'=>$detail['sid']))}">{$detail.sid|getSingleField=###,'shop','name'}</a>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>订餐内容</td>
                                                    <td>
                                                        <table width="500px">
                                                            <tr>
                                                                <td width="170px">名称</td>
                                                                <td>单价</td>
                                                                <td>数量（份）</td>
                                                                <td>其他</td>
                                                                <td>小计</td>
                                                            </tr>
                                                            <foreach name="goods" item="row">
                                                                <tr>
                                                                    <td>{$row.gname}</td>
                                                                    <td>{$row.gprice}</td>
                                                                    <td>{$row.gnum}</td>
                                                                    <td>{$row['is_bag']*$row['gnum']|getOneDot=###} (打包费)</td>
                                                                    <td>{$row['gprice']*$row['gnum']+$row['is_bag']*$row['gnum']|getOneDot=###}</td>
                                                                </tr>
                                                            </foreach>
                                                        </table>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>姓名:</td>
                                                    <td>
                                                        <a href="{:U('User/detail',array('id'=>$detail['uid']))}">{$detail.truename}</a>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>电话:</td>
                                                    <td>
                                                        {$detail.phone}
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>地址:</td>
                                                    <td>
                                                        {$detail.addr}
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>备注:</td>
                                                    <td>{$detail.remark}</td>
                                                </tr>
                                                <tr>
                                                    <td>状态:</td>
                                                    <td>

                                            <if condition="$detail.state eq 0"> 
                                                <label><input type="radio" name="state" value="0"  onclick="checkState($(this))" autocomplete="off" <if condition="$detail.state eq 0">checked</if>> 等待审核
                                                </label>

                                            </if>
                                            <if condition="$detail.state elt 1 && $detail.state neq 9"> 
                                                <label><input type="radio" name="state" value="1" onclick="checkState($(this))" autocomplete="off" <if condition="$detail.state eq 1">checked</if>> 审核完成</label>
                                                <label><input type="radio" name="state" value="5" onclick="checkState($(this))" autocomplete="off" <if condition="$detail.state eq 5">checked</if>> 成功订餐</label>
                                                <label><input type="radio" name="state" value="9" onclick="checkState($(this))" autocomplete="off" <if condition="$detail.state eq -1">checked</if>> 订单失效</label>
                                                <p id="state_input" <if condition="$detail.state eq 9">style="width:360px;"<else/>style="display:none"</if>>失效原因：<input type="text" name="reason" value="{$detail.reason}" >
                                                <span class="g-input-selectbox">
                                                    <select onchange="getReason(this.value)">
                                                        <option value="">请选择</option>
                                                        <option>顾客说没有点过餐。</option>
                                                        <option>捣乱。</option>
                                                        <option>餐厅不开了。</option>

                                                    </select>
                                                </span>
                                                </p>
                                            </if>
                                            <if condition="$detail.state eq 5 or $detail.state eq 9">
                                                {$detail.state|getOrderState}
                                            </if>
                                            </td>
                                            </tr>
                                            <if condition="$detail.state neq 0">
                                                <tr>
                                                    <td></td>
                                                    <td>
                                                        <table>
                                                            <tr>
                                                                <th>操作日志</th>
                                                                <th>操作人</th>
                                                                <th>操作时间</th>
                                                            </tr>
                                                            <foreach name="logs" item="row">
                                                                <tr>
                                                                    <td>{$row.content}</td>
                                                                    <td>{$row.uid|getSingleField=###,'admin_user','name'}</td>
                                                                    <td>{$row.addtime|date="Y-m-d H:i",###}</td>
                                                                </tr>
                                                            </foreach>
                                                        </table>
                                                    </td>
                                                </tr>
                                            </if>
                                            <tr>
                                                <td class="td_left"></td>
                                                <td>
                                                    <input type='hidden' name='id' value='{$Think.get.id}'/>
                                            <if condition="$detail.state neq 5 && $detail.state neq 9">
                                                <button class="btn btn-info btn-sm" type="submit">
                                                    <i class="icon-ok bigger-110 "></i>
                                                    保 存
                                                </button>
                                            </if>

                                            <button class="btn btn-sm reset" type="button" onclick="goUrl(-1)">
                                                <i class="icon-undo bigger-110"></i>
                                                返 回
                                            </button>
                                            </td>
                                            </tr>
                                            </tbody>
                                        </table>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <include file="Public:setting" />
    </div>
</div>
<include file="Public:foot" />